package com.aifast.system.sys.controller;

import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.json.JSONUtil;
import com.aifast.common.base.Controller;
import com.aifast.common.base.R;
import com.aifast.common.global.Const;
import com.aifast.system.fd.dao.FdAreaDao;
import com.aifast.system.fd.dao.FdNationDao;
import com.aifast.system.fd.dao.FdSchoolDao;
import com.aifast.system.sys.dao.SysDictDao;
import com.aifast.system.sys.dao.SysDictDataDao;
import com.aifast.system.sys.entity.SysDictData;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RequestMapping("json")
@RequiredArgsConstructor
@RestController
public class JsonController extends Controller {

    private final SysDictDao sysDictDao;
    private final SysDictDataDao sysDictDataDao;
    private final FdAreaDao areaDao;
    private final FdSchoolDao schoolDao;
    private final FdNationDao nationDao;

    /**
     * 获取静态资源中 json文件数据
     *
     * @param name
     * @return
     * @throws IOException
     */
    @GetMapping("/getJson/{name}")
    public Object getJson(@PathVariable String name) throws IOException {
        String str = ResourceUtil.readUtf8Str(Const.CURRTPATH + "src/main/resources/static/json/" + name);
        return JSONUtil.parse(str);
    }


    @GetMapping("getDict")
    public R getDict(){
        return OK(sysDictDataDao.selectMaps(new QueryWrapper<SysDictData>().select("name","value","type","pid","data_pid","sort","state","remarks")));
    }


}
